feat: Add Pydantic AI provider with PostHog OTel instrumentation#27
feat: Add Pydantic AI provider with PostHog OTel instrumentation#27andrewm4894 wants to merge 1 commit intomainfrom
Conversation
- Add PydanticAIProvider using Pydantic AI's native OTel instrumentation - Integrate with posthog-python's new instrument_pydantic_ai() function - Support multi-turn conversations via message history - Include get_weather and tell_joke tool examples - Add pydantic-ai to requirements.txt 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| try: | ||
| from posthog.ai.pydantic_ai import instrument_pydantic_ai | ||
| except ImportError: | ||
| raise ImportError( | ||
| "PostHog pydantic-ai integration is required. " |
There was a problem hiding this comment.
Pydantic provider always fails due to missing PostHog module
_setup_instrumentation imports posthog.ai.pydantic_ai.instrument_pydantic_ai and raises immediately if it is absent, but python/requirements.txt still pins posthog>=6.6.1, which does not ship that module (the commit text even calls it an “upcoming PR”). With the current dependency set, selecting provider 13 or running run_all_tests will hit this ImportError and the provider cannot be used at all. Pin PostHog to a release that contains the pydantic AI instrumentation or guard the provider until that version is available.
Useful? React with 👍 / 👎.
Summary
PydanticAIProviderusing Pydantic AI's native OpenTelemetry instrumentationinstrument_pydantic_ai()function (from upcoming PR)get_weatherandtell_joketool examplespydantic-aito requirements.txtHow it works
Pydantic AI has native OTel instrumentation via
Agent.instrument_all(). The posthog-python SDK provides a customSpanExporterthat translates these OTel spans into PostHog$ai_generationand$ai_spanevents.Dependencies
This PR depends on a corresponding posthog-python PR that adds the OTel exporter and
instrument_pydantic_ai()function.Test plan
🤖 Generated with Claude Code